﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace VetumaForSharePoint.Code
{
    /// <summary>
    /// Collection of information that is gathered at registration
    /// </summary>
    public class DataFields : ConfigurationElementCollection
    {
        /// <summary>
        /// Get by index
        /// </summary>
        /// <param name="index">Index of data field.</param>
        /// <returns></returns>
        public DataField this[int index]
        {
            get
            {
                return base.BaseGet(index) as DataField;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        /// <summary>
        /// Get by name
        /// </summary>
        /// <param name="name">Name of data field.</param>
        /// <returns></returns>
        public DataField this[string name]
        {
            get
            {
                return base.BaseGet(name) as DataField;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new DataField();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((DataField)element).Name;
        }
    }
}
